package com.xinlu.common.game.action;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateUtils;

import com.xinlu.common.game.bo.ConstantLstBo;
import com.xinlu.common.game.bo.TzjlBo;
import com.xinlu.common.game.form.YxjlForm;
import com.xinlu.derek.common.BaseAction;
import com.xinlu.derek.common.BaseForm;
import com.xinlu.persistence.Users;
import com.xinlu.util.tool.DateUtil;
import com.xinlu.util.tool.PageObject;

public class YxjlAction extends BaseAction {

	YxjlForm fr = new YxjlForm();
	private TzjlBo tzjlBo;

	public void setTzjlBo(TzjlBo tzjlBo) {
		this.tzjlBo = tzjlBo;
	}

	public void setFr(YxjlForm fr) {
		this.fr = fr;
	}

	@Override
	public String doExecute() throws Exception {
		return null;
	}

	@Override
	public void formInit() {
	}

	@Override
	public BaseForm getModel() {
		return fr;
	}

	/**
	 * 加载页面
	 * 
	 * @return
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 */
	public String loadPage() throws IllegalAccessException, InvocationTargetException {

		initYxjl();

		if (ConstantLstBo.isNullOrEmpty(fr.getYhm())) {
			fr.setYhm(((Users) getSession().getAttribute("userinfo")).getUsername());
		}

		Date date = new Date();
		String bgnDate = DateUtil.getFormatDate(DateUtil.YYYY_MM_DD, date);
		String endDate = DateUtil.getFormatDate(DateUtil.YYYY_MM_DD, DateUtils.add(date, 5, 1));
		fr.setBgnDate(bgnDate+ConstantLstBo.getBgnHMS(bgnDate));
		fr.setEndDate(endDate+ConstantLstBo.getBgnHMS(endDate));

		PageObject po = tzjlBo.loadTzjls(fr.getYhm(), fr.getCaiZhong(), fr.getBgnDate(), fr.getEndDate(),fr.getPn());
		fr.setPageObject(po);

		return "yxjl";
	}

	/**
	 * 初始化游戏类型
	 */
	private void initYxjl() {
		fr.setCaiZhongs(ConstantLstBo.getCaiZhongs());
		if (fr.getYxlx() == null) {
			fr.setCaiZhong("--全部--");
		} else {
			fr.setCaiZhong(fr.getYxlx());
		}
	}

	/**
	 * 加载游戏记录
	 * 
	 * @return
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 */
	public String loadYxjl() throws IllegalAccessException, InvocationTargetException {
		fr.setCaiZhongs(ConstantLstBo.getCaiZhongs());
		PageObject po = tzjlBo.loadTzjls(fr.getYhm(), fr.getCaiZhong(), fr.getBgnDate(), fr.getEndDate(),fr.getPn());
		fr.setPageObject(po);

		return "yxjl";
	}

}
